# -*- coding: utf-8 -*-
# pip install peewee pymysql
from peewee import *
from datetime import datetime

db = MySQLDatabase('test', host='127.0.0.1', port=3306, user='root', password='root')

class BaseModel(Model):
    create_time = DateTimeField(default=datetime.now)

    class Meta:
        database = db

class Company(BaseModel):
    name = CharField(verbose_name="公司名称")
    full_name = CharField()
    year = IntegerField(default=2000)

    class Meta:
        table_name = 't_company'

class Music(BaseModel):
    name = CharField(index=True, verbose_name="音乐名称")
    singer = CharField(max_length=32, verbose_name="演唱者")
    duration = CharField(max_length=32, verbose_name="时长")
    _type = CharField(max_length=32, verbose_name="类型")
    commany = CharField(Company, verbose_name="版权所属", backref='musics')

    class Meta:
        table_name = 't_music'

def init_table():
    db.create_tables([Company, Music])

if __name__ == '__main__':
    init_table()

